iT邦幫忙

2024 iThome 鐵人賽

DAY 15
0

在 Mac 裝置上運行 React Android project,出現以下錯誤。

> npx expo run:android
› Building app...
Configuration on demand is an incubating feature.

> Configure project :expo

Using expo modules
  - expo-application (5.9.1)
  - expo-asset (10.0.10)
  - expo-constants (16.0.2)
  - expo-device (6.0.2)
  - expo-file-system (17.0.1)
  - expo-font (12.0.10)
  - expo-keep-awake (13.0.2)
  - expo-modules-core (1.12.24)
  - expo-notifications (0.28.16)


BUILD SUCCESSFUL in 4s
255 actionable tasks: 18 executed, 237 up-to-date
Starting Metro Bundler
(QR code)

› Metro waiting on
com.jim.notification://expo-development-client/?url=http%3A%2F%2F192.168.1.110%3A8081
› Scan the QR code above to open the project in a development build. Learn more

› Using development build
› Press s │ switch to Expo Go

› Press a │ open Android
› Press i │ open iOS simulator
› Press w │ open web

› Press j │ open debugger
› Press r │ reload app
› Press m │ toggle menu
› Press o │ open project code in your editor

› Press ? │ show all commands

› Opening on Android...
CommandError: No development build (com.jim.notification) for this project is installed. Please make and install a development build on the device first.
Learn more
› Opening com.jim.notification://expo-development-client/?url=http%3A%2F%2F192.168.1.110%3A8081 on Pixel_6

› Logs for your project will appear below. Press Ctrl+C to exit.
Android Bundled 505ms node_modules/expo/AppEntry.js (711 modules)

在應用程式的主頁面,想取得 Expo push token 時,出現以下訊息:

Error: Call to function ExpoPushTokenManager.getDevicePushTokenAsync has been rejected
Caused by: java.lang.lllegalStateException: Default FirebaseApp is not initialized in thes process com.jim.notification. Make sure to call FirebaseApp.initializeApp(context) first.

https://ithelp.ithome.com.tw/upload/images/20240925/20151956nXElDaQiUf.png

使用 npx expo prebuild --platform android --clean 來進行預備構建。

> npx expo prebuild --platform android --clean
Warning! Your git working tree is dirty.
It's recommended to commit all your changes before proceeding, so you can revert the changes made by this command if necessary.

✔ Would you like to proceed? … yes

✔ Cleared android code
✔ Created native directory
✔ Updated package.json | no changes
» android: userInterfaceStyle: Install expo-system-ui in your project to enable this feature.
✔ Finished prebuild

資料來源:stakeoverflow - React Native Expo Push Notification ExpoPushTokenManager.getDevicePushTokenAsync has been rejected

重新執行 npx expo run:android,在 Expo push token 有相同的異常訊息。

原來,雖然我們引進了 React Expo Notification library,Android 裝置上的推播邏輯仍需在 Android 原生平台依賴 Google FCM 來實現。


上一篇
[Day 14] Windows - 指定 SDK 路徑
下一篇
[Day 16] 設定 Firebase FCM
系列文
跨平台協同:在 React Native 和 Kotlin 應用中實現無縫交互 -以 Notification 為例30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言